#!/bin/sh
dateStr=$(date +%Y-%m-%d--%H:%M:%S)

# 获取端口为 5236 的PID
PID=$(netstat -tunlp | grep 5236 | awk '{print $7}')

# 检测字符串长度是否为0
if [ -z "$PID" ]; then
  PID="1/"
fi
# 查找字符'/'的位置
index=$(expr index "$PID" /)
index=$(expr "$index" - 1)

echo "$dateStr  --- PID=$PID --- index=$index"
# 提取子字符串
PID=$(echo $PID | cut -b 1-"$index")
echo "$dateStr  --- PID=$PID"

if [ '1' -eq "$PID" ]; then
  systemctl restart DmServiceDMSERVER.service

  echo "$dateStr  restart success!"
else
  echo "$dateStr  need not restart!"
fi

echo "------------------------------------------------------------------------"

